#include "Channel.h"

#include <iostream>
namespace droneswarm
{
    Channel::Channel( EventLoop *loop )
        : loop_( loop )
        , fd_( 0 )
        , events_( 0 )
        , lastEvents_( 0 )
    {
    }

    Channel::Channel( EventLoop *loop, int fd )
        : loop_( loop )
        , fd_( fd )
        , events_( 0 )
        , lastEvents_( 0 )
    {
    }

    Channel::~Channel() {}
    //处理读事件的回调函数
    void Channel::HandleRead()
    {
        if ( readHandler_ )
        {
            readHandler_();
        }
    }
    //处理写事件的回调函数
    void Channel::HandleWrite()
    {
        if ( writeHandler_ )
        {
            writeHandler_();
        }
    }
    //处理错误事件的回调函数
    void Channel::HandleError( int fd, int err_num, std::string msg )
    {
        if ( errorHandler_ )
        {
            errorHandler_( fd, err_num, msg );
        }
    }
    //处理连接事件的回调函数
    void Channel::HandleConn()
    {
        if ( connHandler_ )
        {
            connHandler_();
        }
    }
    //获取当前Channel的文件描述符
    int Channel::get_fd() { return fd_; }
    //设置当前Channel的文件描述符
    void Channel::set_fd( int fd ) { fd_ = fd; }
}  // namespace droneswarm
